home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-30 | 5.2 KB | 230 lines | [TEXT/KAHL] |
- /*****
- * CLaughsApp.cp
- *
- * Implementation of a sample application full of laughter.
- *
- * This sample app is derived from a contribution originally made
- * by Paul Gee (Gee, thanks Paul!).
- *
- * Copyright © 1994 NeoLogic Systems. All rights reserved.
- *
- *****/
-
- #include "NeoTypes.h"
- #include <stdio.h>
- #include CNeoMetaClassH
- #include CNeoDatabaseNativeH
- #include CNeoIDListH
- #include "CLaughsApp.h"
- #include "CLaughsDoc.h"
- #include "CNameIndex.h"
- #include "CPerson.h"
-
- extern OSType gSignature;
-
- int main(void)
- {
- CLaughsApp * app;
-
- app = new CLaughsApp();
- app->Run();
- app->Exit();
-
- return 0;
- }
-
- /***
- * CLaughsApp
- *
- * Initialize the application. If your application class defines its
- * own instance variables or global variables, this is a good place
- * to initialize them.
- *
- ***/
- CLaughsApp::CLaughsApp(void)
- #ifdef __PowerPlant__
- : CNeoAppRoot(kLaughsSig, kLaughsFileType)
- #endif
- {
- CNeoMetaClass * meta;
-
- #if defined(qNeoDebug) && !defined(__MWERKS__)
- gBreakFailure = TRUE;
- #endif
-
- IApplication(kNeoExtraMasters, kNeoRainyDayFund, kNeoCriticalBalance, kNeoToolboxBalance);
-
- printf("Start Laughing...\n\n");
-
- meta = new CNeoMetaClass(kNameIndexID, kNeoNullClassID, "\pCNameIndex", CNameIndex::New, CNameIndex::KeyManager);
-
- meta = new CNeoMetaClass(kNeoIDListID, kNeoNullClassID, "\pCNeoIDList", CNeoIDList::New, CNeoIDList::KeyManager);
-
- meta = new CNeoMetaClass(kPersonID, kNeoPersistID, "\pCPerson", CPerson::New);
- meta->setKey(kNeoSecondaryIndex, kNameIndexID, kPersonID);
-
- meta = new CNeoMetaClass(kJokerID, kPersonID, "\pCJoker", CJoker::New);
- meta->setKey(kNeoSecondaryIndex, kNameIndexID, kPersonID);
-
- meta = new CNeoMetaClass(kJokeID, kNeoPersistID, "\pCJoke", CJoke::New);
-
- meta = new CNeoMetaClass(kClownID, kPersonID, "\pCClown", CClown::New);
- meta->setKey(kNeoSecondaryIndex, kNameIndexID, kPersonID);
-
- meta = new CNeoMetaClass(kPieID, kNeoPersistID, "\pCPie", CPie::New);
-
- // We don't know what we want to do yet.
- // Force user to choose New or Open menu item.
- newWindowOnStartup = FALSE;
- }
-
- /***
- * SetUpFileParameters
- *
- * In this routine you specify the kinds of files your application opens.
- *
- ***/
-
- void CLaughsApp::SetUpFileParameters(void)
-
- {
- inherited::SetUpFileParameters(); /* Be sure to call the default method */
-
- /**
- ** sfNumTypes is the number of file types
- ** your application knows about.
- ** sfFileTypes[] is an array of file types.
- ** You can define up to 4 file types in
- ** sfFileTypes[].
- **
- **/
-
- sfNumTypes = 1;
- sfFileTypes[0] = kLaughsFileType; /* Laughs file type */
-
- /**
- ** Although it's not an instance variable,
- ** this method is a good place to set the
- ** gSignature global variable. Set this global
- ** to your application's signature. You'll use it
- ** to create a file (see CFile::CreateNew()).
- **
- **/
-
- gSignature = kLaughsSig; /* set application signature */
- }
-
- /***
- * createDocument
- *
- * The user chose New from the File menu.
- * In this method, you need to create a document and send it
- * a NewFile() message.
- *
- ***/
- CNeoDoc *CLaughsApp::createDocument(void)
- {
- CLaughsDoc * document = nil;
-
- NEOTRYTO {
- /*
- * Create your document.
- *
- * The arguments indicate whether the document is...
- * printable (FALSE),
- * a new file (TRUE),
- * remote (FALSE).
- */
- document = new CLaughsDoc(FALSE, TRUE, FALSE);
-
- /*
- * Send the document a NewFile() message.
- * The document will open a window, and
- * set up the heart of the application.
- */
- document->NewFile();
- }
- NEOCLEANUP {
- /*
- * This cleanup handler gets executed whether or not a failure
- * occurs.
- */
- if (document) {
- delete document;
- document = nil;
- }
- }
- NEOENDTRYTO;
-
- return document;
- }
-
- /***
- * openDocument
- *
- * The user chose Open… from the File menu.
- * In this method you need to create a document
- * and send it an OpenFile() message.
- *
- * The macSFReply is a good SFReply record that contains
- * the name and vRefNum of the file the user chose to
- * open.
- *
- ***/
-
- void CLaughsApp::OpenDocument(SFReply *macSFReply)
- {
- Boolean remote = FALSE;
- CLaughsDoc * document = nil;
-
- NEOTRY
- {
- // Our parent will check to see if this is a document we have already opened.
- // If we find the file already open by the app, then fDocument will refer to it.
- // If the file is opened but not by this app, then the parent will signal a failure.
- inherited::OpenDocument(macSFReply);
- if (fDocument)
- return;
-
- /**
- ** Create your document.
- **
- **/
- document = new CLaughsDoc(this, TRUE, remote);
-
- /**
- ** Send the document an OpenFile() message.
- ** The document will open a window, open
- ** the file specified in the macSFReply record,
- ** and display it in its window.
- **
- **/
- document->OpenFile(macSFReply);
-
- delete document;
- document = nil;
- }
- NEOCATCH
- {
- /*
- * This exception handler gets executed if a failure occurred
- * anywhere within the scope of the TRY block above. Since
- * this indicates that the document could not be opened, we
- * send it a unrefer message. The exception will propagate up to
- * CSwitchboard's exception handler, which handles displaying
- * an error alert.
- */
-
- if (document)
- delete document;
- }
- NEOENDTRY;
- }
-
- Boolean CLaughsApp::Quit(void)
- {
- running = FALSE;
-
- // Fini!
- return TRUE;
- }